using System.Collections;
using System.Collections.Generic;
using ProjectSurviver;
using QFramework;
using UnityEngine;

public abstract class PowerUp : GamePlayObject
{
    public bool FlyingToPlayer { get; set; }

    private int FlyingToPlayerFrameCount = 0;

    protected abstract void Execute();

    void Update()
    {
        if(FlyingToPlayer)
        {
            if(FlyingToPlayerFrameCount == 0)
            {
                GetComponent<SpriteRenderer>().sortingOrder = 5; // 将Exp的排序层设置为5
            }
            FlyingToPlayerFrameCount++;

            if(Player.Default)
            {
                var direction = Player.Default.DirectionFrom(this); // 获取方向
                var distance = direction.magnitude; // 获取距离

                if(FlyingToPlayerFrameCount <= 15)
                {
                    transform.Translate(direction.normalized * -2 * Time.deltaTime); // 移动到Player
                }
                else
                {
                    transform.Translate(direction.normalized * 7.5f * Time.deltaTime); 
                }

                if(distance < 0.1f)
                {
                    Execute(); // 执行
                }
            }
        }
    }
}
